        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>RevoluteJoint class / box2d_console Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d_console" data-type="RevoluteJoint">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d_console.html">box2d_console</a> &rsaquo; <a href="../box2d_console/RevoluteJoint.html">RevoluteJoint</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>RevoluteJoint</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>A revolute joint constrains two bodies to share a common point while they
are free to rotate about the point. The relative rotation about the shared
point is the joint angle. You can limit the relative rotation with
a joint limit that specifies a lower and upper angle. You can use a motor
to drive the relative rotation about the shared point. A maximum motor torque
is provided so that infinite forces are not generated.</p>
<pre class="source">
class RevoluteJoint extends Joint {
  final Vector localAnchor1;
  final Vector localAnchor2;

  final Vector3 impulse;

  num _motorImpulse;

  // Effective mass for point-to-point constraint.
  final Matrix33 mass;

  // Effective mass for motor/limit angular constraint.
  num motorMass;

  bool _enableMotor;

  num _maxMotorTorque;

  num _motorSpeed;

  bool _enableLimit;

  num referenceAngle;

  /** Limits on the relative rotation of the joint. */
  num lowerAngle;
  num upperAngle;

  int limitState;

  RevoluteJoint(RevoluteJointDef def) :
    super(def),
    localAnchor1 = new Vector(),
    localAnchor2 = new Vector(),
    impulse = new Vector3(),
    _motorImpulse = 0,
    mass = new Matrix33() {
    localAnchor1.setFrom(def.localAnchorA);
    localAnchor2.setFrom(def.localAnchorB);
    referenceAngle = def.referenceAngle;

    _motorImpulse = 0;

    lowerAngle = def.lowerAngle;
    upperAngle = def.upperAngle;
    _maxMotorTorque = def.maxMotorTorque;
    _motorSpeed = def.motorSpeed;
    _enableLimit = def.enableLimit;
    _enableMotor = def.enableMotor;
  }

  void initVelocityConstraints(TimeStep step) {
    final Body b1 = bodyA;
    final Body b2 = bodyB;

    if (_enableMotor || _enableLimit) {
      // You cannot create a rotation limit between bodies that
      // both have fixed rotation.
      assert (b1.invInertia &gt; 0.0 || b2.invInertia &gt; 0.0);
    }

    final Vector r1 = new Vector();
    final Vector r2 = new Vector();

    // Compute the effective mass matrix.
    r1.setFrom(localAnchor1).subLocal(b1.localCenter);
    r2.setFrom(localAnchor2).subLocal(b2.localCenter);
    Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
    Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

    num m1 = b1.invMass, m2 = b2.invMass;
    num i1 = b1.invInertia, i2 = b2.invInertia;

    mass.col1.x = m1 + m2 + r1.y * r1.y * i1 + r2.y * r2.y * i2;
    mass.col2.x = -r1.y * r1.x * i1 - r2.y * r2.x * i2;
    mass.col3.x = -r1.y * i1 - r2.y * i2;
    mass.col1.y = mass.col2.x;
    mass.col2.y = m1 + m2 + r1.x * r1.x * i1 + r2.x * r2.x * i2;
    mass.col3.y = r1.x * i1 + r2.x * i2;
    mass.col1.z = mass.col3.x;
    mass.col2.z = mass.col3.y;
    mass.col3.z = i1 + i2;

    motorMass = i1 + i2;
    if (motorMass &gt; 0.0) {
      motorMass = 1.0 / motorMass;
    }

    if (_enableMotor == false) {
      _motorImpulse = 0.0;
    }

    if (_enableLimit) {
      num jointAngle = b2.sweep.angle - b1.sweep.angle - referenceAngle;
      if ((upperAngle - lowerAngle).abs() &lt; 2.0 * Settings.ANGULAR_SLOP) {
        limitState = LimitState.EQUAL;
      }
      else if (jointAngle &lt;= lowerAngle) {
        if (limitState != LimitState.AT_LOWER) {
          impulse.z = 0.0;
        }
        limitState = LimitState.AT_LOWER;
      }
      else if (jointAngle &gt;= upperAngle) {
        if (limitState != LimitState.AT_UPPER) {
          impulse.z = 0.0;
        }
        limitState = LimitState.AT_UPPER;
      }
      else {
        limitState = LimitState.INACTIVE;
        impulse.z = 0.0;
      }
    }
    else {
      limitState = LimitState.INACTIVE;
    }

    if (step.warmStarting) {
      // Scale impulses to support a variable time step.
      impulse.mulLocal(step.dtRatio);
      _motorImpulse *= step.dtRatio;

      Vector temp = new Vector();
      Vector P = new Vector();
      P.setCoords(impulse.x, impulse.y);

      temp.setFrom(P).mulLocal(m1);
      b1.linearVelocity.subLocal(temp);
      b1.angularVelocity -= i1 * (Vector.crossVectors(r1, P) + _motorImpulse +
          impulse.z);

      temp.setFrom(P).mulLocal(m2);
      b2.linearVelocity.addLocal(temp);
      b2.angularVelocity += i2 * (Vector.crossVectors(r2, P) + _motorImpulse +
          impulse.z);

    } else {
      impulse.setZero();
      _motorImpulse = 0.0;
    }
  }

  void solveVelocityConstraints(final TimeStep step) {
    final Body b1 = bodyA;
    final Body b2 = bodyB;

    final Vector v1 = b1.linearVelocity;
    num w1 = b1.angularVelocity;
    final Vector v2 = b2.linearVelocity;
    num w2 = b2.angularVelocity;

    num m1 = b1.invMass, m2 = b2.invMass;
    num i1 = b1.invInertia, i2 = b2.invInertia;

    // Solve motor constraint.
    if (_enableMotor &amp;&amp; limitState != LimitState.EQUAL) {
      num Cdot = w2 - w1 - _motorSpeed;
      num imp = motorMass * (-Cdot);
      num oldImpulse = _motorImpulse;
      num maxImpulse = step.dt * _maxMotorTorque;
      _motorImpulse = MathBox.clamp(_motorImpulse + imp, -maxImpulse,
          maxImpulse);
      imp = _motorImpulse - oldImpulse;

      w1 -= i1 * imp;
      w2 += i2 * imp;
    }

    final Vector temp = new Vector();
    final Vector r1 = new Vector();
    final Vector r2 = new Vector();

    // Solve limit constraint.
    if (_enableLimit &amp;&amp; limitState != LimitState.INACTIVE) {

      r1.setFrom(localAnchor1).subLocal(b1.localCenter);
      r2.setFrom(localAnchor2).subLocal(b2.localCenter);
      Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
      Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

      final Vector Cdot1 = new Vector();
      final Vector3 Cdot = new Vector3();

      // Solve point-to-point constraint
      Vector.crossNumAndVectorToOut(w1, r1, temp);
      Vector.crossNumAndVectorToOut(w2, r2, Cdot1);
      Cdot1.addLocal(v2).subLocal(v1).subLocal(temp);
      num Cdot2 = w2 - w1;
      Cdot.setCoords(Cdot1.x, Cdot1.y, Cdot2);

      Vector3 imp = new Vector3();
      mass.solve33ToOut(Cdot.negateLocal(), imp);

      if (limitState == LimitState.EQUAL) {
        impulse.addLocal(imp);
      }
      else if (limitState == LimitState.AT_LOWER) {
        num newImpulse = impulse.z + imp.z;
        if (newImpulse &lt; 0.0) {
          mass.solve22ToOut(Cdot1.negateLocal(), temp);
          imp.x = temp.x;
          imp.y = temp.y;
          imp.z = -impulse.z;
          impulse.x += temp.x;
          impulse.y += temp.y;
          impulse.z = 0.0;
        }
      }
      else if (limitState == LimitState.AT_UPPER) {
        num newImpulse = impulse.z + imp.z;
        if (newImpulse &gt; 0.0) {
          mass.solve22ToOut(Cdot1.negateLocal(), temp);
          imp.x = temp.x;
          imp.y = temp.y;
          imp.z = -impulse.z;
          impulse.x += temp.x;
          impulse.y += temp.y;
          impulse.z = 0.0;
        }
      }
      final Vector P = new Vector();

      P.setCoords(imp.x, imp.y);

      temp.setFrom(P).mulLocal(m1);
      v1.subLocal(temp);
      w1 -= i1 * (Vector.crossVectors(r1, P) + imp.z);

      temp.setFrom(P).mulLocal(m2);
      v2.addLocal(temp);
      w2 += i2 * (Vector.crossVectors(r2, P) + imp.z);

    } else {
      r1.setFrom(localAnchor1).subLocal(b1.localCenter);
      r2.setFrom(localAnchor2).subLocal(b2.localCenter);
      Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
      Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

      // Solve point-to-point constraint
      Vector Cdot = new Vector();
      Vector imp = new Vector();

      Vector.crossNumAndVectorToOut(w1, r1, temp);
      Vector.crossNumAndVectorToOut(w2, r2, Cdot);
      Cdot.addLocal(v2).subLocal(v1).subLocal(temp);
      mass.solve22ToOut(Cdot.negateLocal(), imp); // just leave negated

      impulse.x += imp.x;
      impulse.y += imp.y;

      temp.setFrom(imp).mulLocal(m1);
      v1.subLocal(temp);
      w1 -= i1 * Vector.crossVectors(r1, imp);

      temp.setFrom(imp).mulLocal(m2);
      v2.addLocal(temp);
      w2 += i2 * Vector.crossVectors(r2, imp);
    }

    b1.angularVelocity = w1;
    b2.angularVelocity = w2;
  }

  bool solvePositionConstraints(num baumgarte) {
    final Body b1 = bodyA;
    final Body b2 = bodyB;

    num angularError = 0.0;
    num positionError = 0.0;

    // Solve angular limit constraint.
    if (_enableLimit &amp;&amp; limitState != LimitState.INACTIVE) {
      num angle = b2.sweep.angle - b1.sweep.angle - referenceAngle;
      num limitImpulse = 0.0;

      if (limitState == LimitState.EQUAL) {
        // Prevent large angular corrections
        num C = MathBox.clamp(angle - lowerAngle,
            -Settings.MAX_ANGULAR_CORRECTION, Settings.MAX_ANGULAR_CORRECTION);
        limitImpulse = -motorMass * C;
        angularError = C.abs();
      }
      else if (limitState == LimitState.AT_LOWER) {
        num C = angle - lowerAngle;
        angularError = -C;

        // Prevent large angular corrections and allow some slop.
        C = MathBox.clamp(C + Settings.ANGULAR_SLOP,
            -Settings.MAX_ANGULAR_CORRECTION, 0.0);
        limitImpulse = -motorMass * C;
      }
      else if (limitState == LimitState.AT_UPPER) {
        num C = angle - upperAngle;
        angularError = C;

        // Prevent large angular corrections and allow some slop.
        C = MathBox.clamp(C - Settings.ANGULAR_SLOP, 0.0,
            Settings.MAX_ANGULAR_CORRECTION);
        limitImpulse = -motorMass * C;
      }

      b1.sweep.angle -= b1.invInertia * limitImpulse;
      b2.sweep.angle += b2.invInertia * limitImpulse;

      b1.synchronizeTransform();
      b2.synchronizeTransform();
    }

    // Solve point-to-point constraint.
    {
      Vector imp = new Vector();

      Vector r1 = new Vector();
      Vector r2 = new Vector();
      Vector C = new Vector();

      r1.setFrom(localAnchor1).subLocal(b1.localCenter);
      r2.setFrom(localAnchor2).subLocal(b2.localCenter);
      Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
      Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

      C.setFrom(b2.sweep.center).addLocal(r2);
      C.subLocal(b1.sweep.center).subLocal(r1);
      positionError = C.length;

      num invMass1 = b1.invMass, invMass2 = b2.invMass;
      num invI1 = b1.invInertia, invI2 = b2.invInertia;

      // Handle large detachment.
      final num k_allowedStretch = 10.0 * Settings.LINEAR_SLOP;
      if (C.lengthSquared &gt; k_allowedStretch * k_allowedStretch) {
        Vector u = new Vector();

        // Use a particle solution (no rotation).
        num m = invMass1 + invMass2;
        if (m &gt; 0.0) {
          m = 1.0 / m;
        }
        imp.setFrom(C).negateLocal().mulLocal(m);
        final num k_beta = 0.5;
        // using u as temp variable
        u.setFrom(imp).mulLocal(k_beta * invMass1);
        b1.sweep.center.subLocal(u);
        u.setFrom(imp).mulLocal(k_beta * invMass2);
        b2.sweep.center.addLocal(u);

        C.setFrom(b2.sweep.center).addLocal(r2);
        C.subLocal(b1.sweep.center).subLocal(r1);
      }

      Matrix22 K1 = new Matrix22();
      K1.col1.x = invMass1 + invMass2;
      K1.col2.x = 0.0;
      K1.col1.y = 0.0;
      K1.col2.y = invMass1 + invMass2;

      Matrix22 K2 = new Matrix22();
      K2.col1.x = invI1 * r1.y * r1.y;
      K2.col2.x = -invI1 * r1.x * r1.y;
      K2.col1.y = -invI1 * r1.x * r1.y;
      K2.col2.y = invI1 * r1.x * r1.x;

      Matrix22 K3 = new Matrix22();
      K3.col1.x = invI2 * r2.y * r2.y;
      K3.col2.x = -invI2 * r2.x * r2.y;
      K3.col1.y = -invI2 * r2.x * r2.y;
      K3.col2.y = invI2 * r2.x * r2.x;

      K1.addLocal(K2).addLocal(K3);
      K1.solveToOut(C.negateLocal(), imp); // just leave c negated

      // using C as temp variable
      C.setFrom(imp).mulLocal(b1.invMass);
      b1.sweep.center.subLocal(C);
      b1.sweep.angle -= b1.invInertia * Vector.crossVectors(r1, imp);

      C.setFrom(imp).mulLocal(b2.invMass);
      b2.sweep.center.addLocal(C);
      b2.sweep.angle += b2.invInertia * Vector.crossVectors(r2, imp);

      b1.synchronizeTransform();
      b2.synchronizeTransform();
    }

    return positionError &lt;= Settings.LINEAR_SLOP &amp;&amp; angularError &lt;=
        Settings.ANGULAR_SLOP;
  }

  void getAnchorA(Vector argOut) {
    bodyA.getWorldPointToOut(localAnchor1, argOut);
  }

  void getAnchorB(Vector argOut) {
    bodyB.getWorldPointToOut(localAnchor2, argOut);
  }

  void getReactionForce(num inv_dt, Vector argOut) {
    argOut.setCoords(impulse.x, impulse.y).mulLocal(inv_dt);
  }

  num getReactionTorque(num inv_dt) {
    return inv_dt * impulse.z;
  }

  num get jointAngle() {
    final Body b1 = bodyA;
    final Body b2 = bodyB;
    return b2.sweep.angle - b1.sweep.angle - referenceAngle;
  }

  num get jointSpeed() {
    final Body b1 = bodyA;
    final Body b2 = bodyB;
    return b2.angularVelocity - b1.angularVelocity;
  }

  bool get motorEnabled() {
    return _enableMotor;
  }

  void set motorEnabled(bool flag) {
    bodyA.awake = true;
    bodyB.awake = true;
    _enableMotor = flag;
  }

  num get motorTorque() {
    return _motorImpulse;
  }

  void set motorSpeed(num speed) {
    bodyA.awake = true;
    bodyB.awake = true;
    _motorSpeed = speed;
  }

  num get motorSpeed() {
    return _motorSpeed;
  }

  num get maxMotorTorque() {
    return _maxMotorTorque;
  }

  void set maxMotorTorque(num torque) {
    bodyA.awake = true;
    bodyB.awake = true;
    _maxMotorTorque = torque;
  }

  bool get limitEnabled() {
    return _enableLimit;
  }

  void set limitEnabled(bool flag) {
    bodyA.awake = true;
    bodyB.awake = true;
    _enableLimit = flag;
  }

  void setLimits(final num lower, final num upper) {
    assert (lower &lt;= upper);
    bodyA.awake = true;
    bodyB.awake = true;
    lowerAngle = lower;
    upperAngle = upper;
  }
}
</pre>
</div>
<h3>Extends</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../box2d_console/Joint.html">Joint</a></span>&nbsp;&gt;&nbsp;<span class="type-box"><span class="icon-class"></span><strong>RevoluteJoint</strong></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="RevoluteJoint">
<button class="show-code">Code</button>
new <strong>RevoluteJoint</strong>(<a href="../box2d_console/RevoluteJointDef.html">RevoluteJointDef</a> def) <a class="anchor-link" href="#RevoluteJoint"
              title="Permalink to RevoluteJoint.RevoluteJoint">#</a></h4>
<div class="doc">
<pre class="source">
RevoluteJoint(RevoluteJointDef def) :
  super(def),
  localAnchor1 = new Vector(),
  localAnchor2 = new Vector(),
  impulse = new Vector3(),
  _motorImpulse = 0,
  mass = new Matrix33() {
  localAnchor1.setFrom(def.localAnchorA);
  localAnchor2.setFrom(def.localAnchorB);
  referenceAngle = def.referenceAngle;

  _motorImpulse = 0;

  lowerAngle = def.lowerAngle;
  upperAngle = def.upperAngle;
  _maxMotorTorque = def.maxMotorTorque;
  _motorSpeed = def.motorSpeed;
  _enableLimit = def.enableLimit;
  _enableMotor = def.enableMotor;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field inherited"><h4 id="active">
<button class="show-code">Code</button>
final bool         <strong>active</strong> <a class="anchor-link"
            href="#active"
            title="Permalink to RevoluteJoint.active">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<p>Short-cut function to determine if either body is inactive.</p>
<pre class="source">
bool get active() {
  return bodyA.active &amp;&amp; bodyB.active;
}
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyA">
<button class="show-code">Code</button>
<a href="../box2d_console/Body.html">Body</a>         <strong>bodyA</strong> <a class="anchor-link"
            href="#bodyA"
            title="Permalink to RevoluteJoint.bodyA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
Body bodyA;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyB">
<button class="show-code">Code</button>
<a href="../box2d_console/Body.html">Body</a>         <strong>bodyB</strong> <a class="anchor-link"
            href="#bodyB"
            title="Permalink to RevoluteJoint.bodyB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
Body bodyB;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="collideConnected">
<button class="show-code">Code</button>
bool         <strong>collideConnected</strong> <a class="anchor-link"
            href="#collideConnected"
            title="Permalink to RevoluteJoint.collideConnected">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bool collideConnected;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeA">
<button class="show-code">Code</button>
<a href="../box2d_console/JointEdge.html">JointEdge</a>         <strong>edgeA</strong> <a class="anchor-link"
            href="#edgeA"
            title="Permalink to RevoluteJoint.edgeA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
JointEdge edgeA;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeB">
<button class="show-code">Code</button>
<a href="../box2d_console/JointEdge.html">JointEdge</a>         <strong>edgeB</strong> <a class="anchor-link"
            href="#edgeB"
            title="Permalink to RevoluteJoint.edgeB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
JointEdge edgeB;
</pre>
</div>
</div>
<div class="field"><h4 id="impulse">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector3.html">Vector3</a>         <strong>impulse</strong> <a class="anchor-link"
            href="#impulse"
            title="Permalink to RevoluteJoint.impulse">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector3 impulse;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIA">
<button class="show-code">Code</button>
num         <strong>invIA</strong> <a class="anchor-link"
            href="#invIA"
            title="Permalink to RevoluteJoint.invIA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
num invIA;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIB">
<button class="show-code">Code</button>
num         <strong>invIB</strong> <a class="anchor-link"
            href="#invIB"
            title="Permalink to RevoluteJoint.invIB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
num invIB;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassA">
<button class="show-code">Code</button>
num         <strong>invMassA</strong> <a class="anchor-link"
            href="#invMassA"
            title="Permalink to RevoluteJoint.invMassA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
num invMassA;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassB">
<button class="show-code">Code</button>
num         <strong>invMassB</strong> <a class="anchor-link"
            href="#invMassB"
            title="Permalink to RevoluteJoint.invMassB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
num invMassB;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="islandFlag">
<button class="show-code">Code</button>
bool         <strong>islandFlag</strong> <a class="anchor-link"
            href="#islandFlag"
            title="Permalink to RevoluteJoint.islandFlag">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bool islandFlag;
</pre>
</div>
</div>
<div class="field"><h4 id="jointAngle">
<button class="show-code">Code</button>
final num         <strong>jointAngle</strong> <a class="anchor-link"
            href="#jointAngle"
            title="Permalink to RevoluteJoint.jointAngle">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get jointAngle() {
  final Body b1 = bodyA;
  final Body b2 = bodyB;
  return b2.sweep.angle - b1.sweep.angle - referenceAngle;
}
</pre>
</div>
</div>
<div class="field"><h4 id="jointSpeed">
<button class="show-code">Code</button>
final num         <strong>jointSpeed</strong> <a class="anchor-link"
            href="#jointSpeed"
            title="Permalink to RevoluteJoint.jointSpeed">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get jointSpeed() {
  final Body b1 = bodyA;
  final Body b2 = bodyB;
  return b2.angularVelocity - b1.angularVelocity;
}
</pre>
</div>
</div>
<div class="field"><h4 id="limitEnabled">
<button class="show-code">Code</button>
bool         <strong>limitEnabled</strong> <a class="anchor-link"
            href="#limitEnabled"
            title="Permalink to RevoluteJoint.limitEnabled">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bool get limitEnabled() {
  return _enableLimit;
}
</pre>
<pre class="source">
void set limitEnabled(bool flag) {
  bodyA.awake = true;
  bodyB.awake = true;
  _enableLimit = flag;
}
</pre>
</div>
</div>
<div class="field"><h4 id="limitState">
<button class="show-code">Code</button>
int         <strong>limitState</strong> <a class="anchor-link"
            href="#limitState"
            title="Permalink to RevoluteJoint.limitState">#</a>
        </h4>
        <div class="doc">
<pre class="source">
int limitState;
</pre>
</div>
</div>
<div class="field"><h4 id="localAnchor1">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>localAnchor1</strong> <a class="anchor-link"
            href="#localAnchor1"
            title="Permalink to RevoluteJoint.localAnchor1">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector localAnchor1;
</pre>
</div>
</div>
<div class="field"><h4 id="localAnchor2">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>localAnchor2</strong> <a class="anchor-link"
            href="#localAnchor2"
            title="Permalink to RevoluteJoint.localAnchor2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector localAnchor2;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterA">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>localCenterA</strong> <a class="anchor-link"
            href="#localCenterA"
            title="Permalink to RevoluteJoint.localCenterA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
final Vector localCenterA;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterB">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>localCenterB</strong> <a class="anchor-link"
            href="#localCenterB"
            title="Permalink to RevoluteJoint.localCenterB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
final Vector localCenterB;
</pre>
</div>
</div>
<div class="field"><h4 id="lowerAngle">
<button class="show-code">Code</button>
num         <strong>lowerAngle</strong> <a class="anchor-link"
            href="#lowerAngle"
            title="Permalink to RevoluteJoint.lowerAngle">#</a>
        </h4>
        <div class="doc">
<p>Limits on the relative rotation of the joint.</p>
<pre class="source">
num lowerAngle;
</pre>
</div>
</div>
<div class="field"><h4 id="mass">
<button class="show-code">Code</button>
final <a href="../box2d_console/Matrix33.html">Matrix33</a>         <strong>mass</strong> <a class="anchor-link"
            href="#mass"
            title="Permalink to RevoluteJoint.mass">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Matrix33 mass;
</pre>
</div>
</div>
<div class="field"><h4 id="maxMotorTorque">
<button class="show-code">Code</button>
num         <strong>maxMotorTorque</strong> <a class="anchor-link"
            href="#maxMotorTorque"
            title="Permalink to RevoluteJoint.maxMotorTorque">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get maxMotorTorque() {
  return _maxMotorTorque;
}
</pre>
<pre class="source">
void set maxMotorTorque(num torque) {
  bodyA.awake = true;
  bodyB.awake = true;
  _maxMotorTorque = torque;
}
</pre>
</div>
</div>
<div class="field"><h4 id="motorEnabled">
<button class="show-code">Code</button>
bool         <strong>motorEnabled</strong> <a class="anchor-link"
            href="#motorEnabled"
            title="Permalink to RevoluteJoint.motorEnabled">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bool get motorEnabled() {
  return _enableMotor;
}
</pre>
<pre class="source">
void set motorEnabled(bool flag) {
  bodyA.awake = true;
  bodyB.awake = true;
  _enableMotor = flag;
}
</pre>
</div>
</div>
<div class="field"><h4 id="motorMass">
<button class="show-code">Code</button>
num         <strong>motorMass</strong> <a class="anchor-link"
            href="#motorMass"
            title="Permalink to RevoluteJoint.motorMass">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num motorMass;
</pre>
</div>
</div>
<div class="field"><h4 id="motorSpeed">
<button class="show-code">Code</button>
num         <strong>motorSpeed</strong> <a class="anchor-link"
            href="#motorSpeed"
            title="Permalink to RevoluteJoint.motorSpeed">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get motorSpeed() {
  return _motorSpeed;
}
</pre>
<pre class="source">
void set motorSpeed(num speed) {
  bodyA.awake = true;
  bodyB.awake = true;
  _motorSpeed = speed;
}
</pre>
</div>
</div>
<div class="field"><h4 id="motorTorque">
<button class="show-code">Code</button>
final num         <strong>motorTorque</strong> <a class="anchor-link"
            href="#motorTorque"
            title="Permalink to RevoluteJoint.motorTorque">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get motorTorque() {
  return _motorImpulse;
}
</pre>
</div>
</div>
<div class="field"><h4 id="referenceAngle">
<button class="show-code">Code</button>
num         <strong>referenceAngle</strong> <a class="anchor-link"
            href="#referenceAngle"
            title="Permalink to RevoluteJoint.referenceAngle">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num referenceAngle;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="runtimeType">
<button class="show-code">Code</button>
final Type         <strong>runtimeType</strong> <a class="anchor-link"
            href="#runtimeType"
            title="Permalink to RevoluteJoint.runtimeType">#</a>
        </h4>
        <div class="inherited-from">inherited from Object </div><div class="doc">
<p>A representation of the runtime type of the object.</p>
<pre class="source">
external Type get runtimeType;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="type">
<button class="show-code">Code</button>
int         <strong>type</strong> <a class="anchor-link"
            href="#type"
            title="Permalink to RevoluteJoint.type">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
int type;
</pre>
</div>
</div>
<div class="field"><h4 id="upperAngle">
<button class="show-code">Code</button>
num         <strong>upperAngle</strong> <a class="anchor-link"
            href="#upperAngle"
            title="Permalink to RevoluteJoint.upperAngle">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num upperAngle;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="userData">
<button class="show-code">Code</button>
Object         <strong>userData</strong> <a class="anchor-link"
            href="#userData"
            title="Permalink to RevoluteJoint.userData">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
Object userData;
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method inherited"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to RevoluteJoint.operator ==">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>The equality operator.</p>
<p>The default behavior for all <code>Object</code>s is to return true if and
only if <code>this</code> and 
<span class="param">other</span> are the same object.</p>
<p>If a subclass overrides the equality operator it should override
the <code>hashCode</code> method as well to maintain consistency.</p>
<pre class="source">
bool operator ==(other) =&gt; identical(this, other);
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method inherited"><h4 id="destructor">
<button class="show-code">Code</button>
void <strong>destructor</strong>() <a class="anchor-link" href="#destructor"
              title="Permalink to RevoluteJoint.destructor">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<p>Override to handle destruction of joint</p>
<pre class="source">
void destructor() { }
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorA">
<button class="show-code">Code</button>
void <strong>getAnchorA</strong>(<a href="../box2d_console/Vector.html">Vector</a> argOut) <a class="anchor-link" href="#getAnchorA"
              title="Permalink to RevoluteJoint.getAnchorA">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyA in world coordinates.</p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d_console/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorA(Vector argOut) {
  bodyA.getWorldPointToOut(localAnchor1, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorB">
<button class="show-code">Code</button>
void <strong>getAnchorB</strong>(<a href="../box2d_console/Vector.html">Vector</a> argOut) <a class="anchor-link" href="#getAnchorB"
              title="Permalink to RevoluteJoint.getAnchorB">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyB in world coordinates.</p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d_console/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorB(Vector argOut) {
  bodyB.getWorldPointToOut(localAnchor2, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionForce">
<button class="show-code">Code</button>
void <strong>getReactionForce</strong>(num inv_dt, <a href="../box2d_console/Vector.html">Vector</a> argOut) <a class="anchor-link" href="#getReactionForce"
              title="Permalink to RevoluteJoint.getReactionForce">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction force on body2 at the joint anchor in Newtons.</p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d_console/Joint.html">Joint</a> </div></div>
<pre class="source">
void getReactionForce(num inv_dt, Vector argOut) {
  argOut.setCoords(impulse.x, impulse.y).mulLocal(inv_dt);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionTorque">
<button class="show-code">Code</button>
num <strong>getReactionTorque</strong>(num inv_dt) <a class="anchor-link" href="#getReactionTorque"
              title="Permalink to RevoluteJoint.getReactionTorque">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction torque on body2 in N*m.</p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d_console/Joint.html">Joint</a> </div></div>
<pre class="source">
num getReactionTorque(num inv_dt) {
  return inv_dt * impulse.z;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="hashCode">
<button class="show-code">Code</button>
int <strong>hashCode</strong>() <a class="anchor-link" href="#hashCode"
              title="Permalink to RevoluteJoint.hashCode">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Get a hash code for this object.</p>
<p>All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator <code>==</code>. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.</p>
<p>If a subclass overrides <code>hashCode</code> it should override the
equality operator as well to maintain consistency.</p>
<pre class="source">
external int hashCode();
</pre>
</div>
</div>
<div class="method"><h4 id="initVelocityConstraints">
<button class="show-code">Code</button>
void <strong>initVelocityConstraints</strong>(<a href="../box2d_console/TimeStep.html">TimeStep</a> step) <a class="anchor-link" href="#initVelocityConstraints"
              title="Permalink to RevoluteJoint.initVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void initVelocityConstraints(TimeStep step) {
  final Body b1 = bodyA;
  final Body b2 = bodyB;

  if (_enableMotor || _enableLimit) {
    // You cannot create a rotation limit between bodies that
    // both have fixed rotation.
    assert (b1.invInertia &gt; 0.0 || b2.invInertia &gt; 0.0);
  }

  final Vector r1 = new Vector();
  final Vector r2 = new Vector();

  // Compute the effective mass matrix.
  r1.setFrom(localAnchor1).subLocal(b1.localCenter);
  r2.setFrom(localAnchor2).subLocal(b2.localCenter);
  Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
  Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

  num m1 = b1.invMass, m2 = b2.invMass;
  num i1 = b1.invInertia, i2 = b2.invInertia;

  mass.col1.x = m1 + m2 + r1.y * r1.y * i1 + r2.y * r2.y * i2;
  mass.col2.x = -r1.y * r1.x * i1 - r2.y * r2.x * i2;
  mass.col3.x = -r1.y * i1 - r2.y * i2;
  mass.col1.y = mass.col2.x;
  mass.col2.y = m1 + m2 + r1.x * r1.x * i1 + r2.x * r2.x * i2;
  mass.col3.y = r1.x * i1 + r2.x * i2;
  mass.col1.z = mass.col3.x;
  mass.col2.z = mass.col3.y;
  mass.col3.z = i1 + i2;

  motorMass = i1 + i2;
  if (motorMass &gt; 0.0) {
    motorMass = 1.0 / motorMass;
  }

  if (_enableMotor == false) {
    _motorImpulse = 0.0;
  }

  if (_enableLimit) {
    num jointAngle = b2.sweep.angle - b1.sweep.angle - referenceAngle;
    if ((upperAngle - lowerAngle).abs() &lt; 2.0 * Settings.ANGULAR_SLOP) {
      limitState = LimitState.EQUAL;
    }
    else if (jointAngle &lt;= lowerAngle) {
      if (limitState != LimitState.AT_LOWER) {
        impulse.z = 0.0;
      }
      limitState = LimitState.AT_LOWER;
    }
    else if (jointAngle &gt;= upperAngle) {
      if (limitState != LimitState.AT_UPPER) {
        impulse.z = 0.0;
      }
      limitState = LimitState.AT_UPPER;
    }
    else {
      limitState = LimitState.INACTIVE;
      impulse.z = 0.0;
    }
  }
  else {
    limitState = LimitState.INACTIVE;
  }

  if (step.warmStarting) {
    // Scale impulses to support a variable time step.
    impulse.mulLocal(step.dtRatio);
    _motorImpulse *= step.dtRatio;

    Vector temp = new Vector();
    Vector P = new Vector();
    P.setCoords(impulse.x, impulse.y);

    temp.setFrom(P).mulLocal(m1);
    b1.linearVelocity.subLocal(temp);
    b1.angularVelocity -= i1 * (Vector.crossVectors(r1, P) + _motorImpulse +
        impulse.z);

    temp.setFrom(P).mulLocal(m2);
    b2.linearVelocity.addLocal(temp);
    b2.angularVelocity += i2 * (Vector.crossVectors(r2, P) + _motorImpulse +
        impulse.z);

  } else {
    impulse.setZero();
    _motorImpulse = 0.0;
  }
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Joint">
<button class="show-code">Code</button>
new <strong>Joint</strong>(<a href="../box2d_console/JointDef.html">JointDef</a> def) <a class="anchor-link" href="#Joint"
              title="Permalink to RevoluteJoint.Joint">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
Joint(JointDef def) :
  type = def.type,
  _prev = null,
  _next = null,
  bodyA = def.bodyA,
  bodyB = def.bodyB,
  collideConnected = def.collideConnected,
  islandFlag = false,
  userData = def.userData,

  localCenterA = new Vector(),
  localCenterB = new Vector(),
  edgeA = new JointEdge(),
  edgeB = new JointEdge() { }
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Joint.create">
<button class="show-code">Code</button>
factory <strong>Joint.create</strong>(<a href="../box2d_console/World.html">World</a> argWorld, <a href="../box2d_console/JointDef.html">JointDef</a> def) <a class="anchor-link" href="#Joint.create"
              title="Permalink to RevoluteJoint.Joint.create">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d_console/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
factory Joint.create(World argWorld, JointDef def) {
  switch(def.type){
    case JointType.MOUSE:
      throw new NotImplementedException();
      //  return new MouseJoint(def);
    case JointType.DISTANCE:
      return new DistanceJoint(def);
    case JointType.PRISMATIC:
      throw new NotImplementedException();
      //  return new PrismaticJoint(def);
    case JointType.REVOLUTE:
      return new RevoluteJoint(def);
    case JointType.WELD:
      throw new NotImplementedException();
      //return new WeldJoint(def);
    case JointType.FRICTION:
      return new FrictionJoint(def);
    case JointType.LINE:
      throw new NotImplementedException();
      //return new LineJoint(def);
    case JointType.GEAR:
      throw new NotImplementedException();
      //return new GearJoint(def);
    case JointType.PULLEY:
      throw new NotImplementedException();
      //return new PulleyJoint(def);
    case JointType.CONSTANT_VOLUME:
      return new ConstantVolumeJoint(argWorld, def);
  }
  return null;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="noSuchMethod">
<button class="show-code">Code</button>
<strong>noSuchMethod</strong>(String name, List args) <a class="anchor-link" href="#noSuchMethod"
              title="Permalink to RevoluteJoint.noSuchMethod">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p><code>noSuchMethod</code> is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to <code>noSuchMethod</code>. If <code>noSuchMethod</code>
returns a value, that value becomes the result of the original
invocation.</p>
<p>The default behavior of <code>noSuchMethod</code> is to throw a
<code>noSuchMethodError</code>.</p>
<pre class="source">
external Dynamic noSuchMethod(String name, List args);
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Object">
<button class="show-code">Code</button>
const <strong>Object</strong>() <a class="anchor-link" href="#Object"
              title="Permalink to RevoluteJoint.Object">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Creates a new <code>Object</code> instance.</p>
<p><code>Object</code> instances have no meaningful state, and are only useful
through their identity. An <code>Object</code> instance is equal to itself
only.</p>
<pre class="source">
const Object();
</pre>
</div>
</div>
<div class="method"><h4 id="RevoluteJoint">
<button class="show-code">Code</button>
new <strong>RevoluteJoint</strong>(<a href="../box2d_console/RevoluteJointDef.html">RevoluteJointDef</a> def) <a class="anchor-link" href="#RevoluteJoint"
              title="Permalink to RevoluteJoint.RevoluteJoint">#</a></h4>
<div class="doc">
<pre class="source">
RevoluteJoint(RevoluteJointDef def) :
  super(def),
  localAnchor1 = new Vector(),
  localAnchor2 = new Vector(),
  impulse = new Vector3(),
  _motorImpulse = 0,
  mass = new Matrix33() {
  localAnchor1.setFrom(def.localAnchorA);
  localAnchor2.setFrom(def.localAnchorB);
  referenceAngle = def.referenceAngle;

  _motorImpulse = 0;

  lowerAngle = def.lowerAngle;
  upperAngle = def.upperAngle;
  _maxMotorTorque = def.maxMotorTorque;
  _motorSpeed = def.motorSpeed;
  _enableLimit = def.enableLimit;
  _enableMotor = def.enableMotor;
}
</pre>
</div>
</div>
<div class="method"><h4 id="setLimits">
<button class="show-code">Code</button>
void <strong>setLimits</strong>(num lower, num upper) <a class="anchor-link" href="#setLimits"
              title="Permalink to RevoluteJoint.setLimits">#</a></h4>
<div class="doc">
<pre class="source">
void setLimits(final num lower, final num upper) {
  assert (lower &lt;= upper);
  bodyA.awake = true;
  bodyB.awake = true;
  lowerAngle = lower;
  upperAngle = upper;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solvePositionConstraints">
<button class="show-code">Code</button>
bool <strong>solvePositionConstraints</strong>(num baumgarte) <a class="anchor-link" href="#solvePositionConstraints"
              title="Permalink to RevoluteJoint.solvePositionConstraints">#</a></h4>
<div class="doc">
<div class="inherited">
<p>This returns true if the position errors are within tolerance.</p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d_console/Joint.html">Joint</a> </div></div>
<pre class="source">
bool solvePositionConstraints(num baumgarte) {
  final Body b1 = bodyA;
  final Body b2 = bodyB;

  num angularError = 0.0;
  num positionError = 0.0;

  // Solve angular limit constraint.
  if (_enableLimit &amp;&amp; limitState != LimitState.INACTIVE) {
    num angle = b2.sweep.angle - b1.sweep.angle - referenceAngle;
    num limitImpulse = 0.0;

    if (limitState == LimitState.EQUAL) {
      // Prevent large angular corrections
      num C = MathBox.clamp(angle - lowerAngle,
          -Settings.MAX_ANGULAR_CORRECTION, Settings.MAX_ANGULAR_CORRECTION);
      limitImpulse = -motorMass * C;
      angularError = C.abs();
    }
    else if (limitState == LimitState.AT_LOWER) {
      num C = angle - lowerAngle;
      angularError = -C;

      // Prevent large angular corrections and allow some slop.
      C = MathBox.clamp(C + Settings.ANGULAR_SLOP,
          -Settings.MAX_ANGULAR_CORRECTION, 0.0);
      limitImpulse = -motorMass * C;
    }
    else if (limitState == LimitState.AT_UPPER) {
      num C = angle - upperAngle;
      angularError = C;

      // Prevent large angular corrections and allow some slop.
      C = MathBox.clamp(C - Settings.ANGULAR_SLOP, 0.0,
          Settings.MAX_ANGULAR_CORRECTION);
      limitImpulse = -motorMass * C;
    }

    b1.sweep.angle -= b1.invInertia * limitImpulse;
    b2.sweep.angle += b2.invInertia * limitImpulse;

    b1.synchronizeTransform();
    b2.synchronizeTransform();
  }

  // Solve point-to-point constraint.
  {
    Vector imp = new Vector();

    Vector r1 = new Vector();
    Vector r2 = new Vector();
    Vector C = new Vector();

    r1.setFrom(localAnchor1).subLocal(b1.localCenter);
    r2.setFrom(localAnchor2).subLocal(b2.localCenter);
    Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
    Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

    C.setFrom(b2.sweep.center).addLocal(r2);
    C.subLocal(b1.sweep.center).subLocal(r1);
    positionError = C.length;

    num invMass1 = b1.invMass, invMass2 = b2.invMass;
    num invI1 = b1.invInertia, invI2 = b2.invInertia;

    // Handle large detachment.
    final num k_allowedStretch = 10.0 * Settings.LINEAR_SLOP;
    if (C.lengthSquared &gt; k_allowedStretch * k_allowedStretch) {
      Vector u = new Vector();

      // Use a particle solution (no rotation).
      num m = invMass1 + invMass2;
      if (m &gt; 0.0) {
        m = 1.0 / m;
      }
      imp.setFrom(C).negateLocal().mulLocal(m);
      final num k_beta = 0.5;
      // using u as temp variable
      u.setFrom(imp).mulLocal(k_beta * invMass1);
      b1.sweep.center.subLocal(u);
      u.setFrom(imp).mulLocal(k_beta * invMass2);
      b2.sweep.center.addLocal(u);

      C.setFrom(b2.sweep.center).addLocal(r2);
      C.subLocal(b1.sweep.center).subLocal(r1);
    }

    Matrix22 K1 = new Matrix22();
    K1.col1.x = invMass1 + invMass2;
    K1.col2.x = 0.0;
    K1.col1.y = 0.0;
    K1.col2.y = invMass1 + invMass2;

    Matrix22 K2 = new Matrix22();
    K2.col1.x = invI1 * r1.y * r1.y;
    K2.col2.x = -invI1 * r1.x * r1.y;
    K2.col1.y = -invI1 * r1.x * r1.y;
    K2.col2.y = invI1 * r1.x * r1.x;

    Matrix22 K3 = new Matrix22();
    K3.col1.x = invI2 * r2.y * r2.y;
    K3.col2.x = -invI2 * r2.x * r2.y;
    K3.col1.y = -invI2 * r2.x * r2.y;
    K3.col2.y = invI2 * r2.x * r2.x;

    K1.addLocal(K2).addLocal(K3);
    K1.solveToOut(C.negateLocal(), imp); // just leave c negated

    // using C as temp variable
    C.setFrom(imp).mulLocal(b1.invMass);
    b1.sweep.center.subLocal(C);
    b1.sweep.angle -= b1.invInertia * Vector.crossVectors(r1, imp);

    C.setFrom(imp).mulLocal(b2.invMass);
    b2.sweep.center.addLocal(C);
    b2.sweep.angle += b2.invInertia * Vector.crossVectors(r2, imp);

    b1.synchronizeTransform();
    b2.synchronizeTransform();
  }

  return positionError &lt;= Settings.LINEAR_SLOP &amp;&amp; angularError &lt;=
      Settings.ANGULAR_SLOP;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solveVelocityConstraints">
<button class="show-code">Code</button>
void <strong>solveVelocityConstraints</strong>(<a href="../box2d_console/TimeStep.html">TimeStep</a> step) <a class="anchor-link" href="#solveVelocityConstraints"
              title="Permalink to RevoluteJoint.solveVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void solveVelocityConstraints(final TimeStep step) {
  final Body b1 = bodyA;
  final Body b2 = bodyB;

  final Vector v1 = b1.linearVelocity;
  num w1 = b1.angularVelocity;
  final Vector v2 = b2.linearVelocity;
  num w2 = b2.angularVelocity;

  num m1 = b1.invMass, m2 = b2.invMass;
  num i1 = b1.invInertia, i2 = b2.invInertia;

  // Solve motor constraint.
  if (_enableMotor &amp;&amp; limitState != LimitState.EQUAL) {
    num Cdot = w2 - w1 - _motorSpeed;
    num imp = motorMass * (-Cdot);
    num oldImpulse = _motorImpulse;
    num maxImpulse = step.dt * _maxMotorTorque;
    _motorImpulse = MathBox.clamp(_motorImpulse + imp, -maxImpulse,
        maxImpulse);
    imp = _motorImpulse - oldImpulse;

    w1 -= i1 * imp;
    w2 += i2 * imp;
  }

  final Vector temp = new Vector();
  final Vector r1 = new Vector();
  final Vector r2 = new Vector();

  // Solve limit constraint.
  if (_enableLimit &amp;&amp; limitState != LimitState.INACTIVE) {

    r1.setFrom(localAnchor1).subLocal(b1.localCenter);
    r2.setFrom(localAnchor2).subLocal(b2.localCenter);
    Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
    Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

    final Vector Cdot1 = new Vector();
    final Vector3 Cdot = new Vector3();

    // Solve point-to-point constraint
    Vector.crossNumAndVectorToOut(w1, r1, temp);
    Vector.crossNumAndVectorToOut(w2, r2, Cdot1);
    Cdot1.addLocal(v2).subLocal(v1).subLocal(temp);
    num Cdot2 = w2 - w1;
    Cdot.setCoords(Cdot1.x, Cdot1.y, Cdot2);

    Vector3 imp = new Vector3();
    mass.solve33ToOut(Cdot.negateLocal(), imp);

    if (limitState == LimitState.EQUAL) {
      impulse.addLocal(imp);
    }
    else if (limitState == LimitState.AT_LOWER) {
      num newImpulse = impulse.z + imp.z;
      if (newImpulse &lt; 0.0) {
        mass.solve22ToOut(Cdot1.negateLocal(), temp);
        imp.x = temp.x;
        imp.y = temp.y;
        imp.z = -impulse.z;
        impulse.x += temp.x;
        impulse.y += temp.y;
        impulse.z = 0.0;
      }
    }
    else if (limitState == LimitState.AT_UPPER) {
      num newImpulse = impulse.z + imp.z;
      if (newImpulse &gt; 0.0) {
        mass.solve22ToOut(Cdot1.negateLocal(), temp);
        imp.x = temp.x;
        imp.y = temp.y;
        imp.z = -impulse.z;
        impulse.x += temp.x;
        impulse.y += temp.y;
        impulse.z = 0.0;
      }
    }
    final Vector P = new Vector();

    P.setCoords(imp.x, imp.y);

    temp.setFrom(P).mulLocal(m1);
    v1.subLocal(temp);
    w1 -= i1 * (Vector.crossVectors(r1, P) + imp.z);

    temp.setFrom(P).mulLocal(m2);
    v2.addLocal(temp);
    w2 += i2 * (Vector.crossVectors(r2, P) + imp.z);

  } else {
    r1.setFrom(localAnchor1).subLocal(b1.localCenter);
    r2.setFrom(localAnchor2).subLocal(b2.localCenter);
    Matrix22.mulMatrixAndVectorToOut(b1.originTransform.rotation, r1, r1);
    Matrix22.mulMatrixAndVectorToOut(b2.originTransform.rotation, r2, r2);

    // Solve point-to-point constraint
    Vector Cdot = new Vector();
    Vector imp = new Vector();

    Vector.crossNumAndVectorToOut(w1, r1, temp);
    Vector.crossNumAndVectorToOut(w2, r2, Cdot);
    Cdot.addLocal(v2).subLocal(v1).subLocal(temp);
    mass.solve22ToOut(Cdot.negateLocal(), imp); // just leave negated

    impulse.x += imp.x;
    impulse.y += imp.y;

    temp.setFrom(imp).mulLocal(m1);
    v1.subLocal(temp);
    w1 -= i1 * Vector.crossVectors(r1, imp);

    temp.setFrom(imp).mulLocal(m2);
    v2.addLocal(temp);
    w2 += i2 * Vector.crossVectors(r2, imp);
  }

  b1.angularVelocity = w1;
  b2.angularVelocity = w2;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to RevoluteJoint.toString">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Returns a string representation of this object.</p>
<pre class="source">
external String toString();
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
